﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PhoenixCrabV6.Engine.Screens;

namespace PhoenixCrabV6.Engine.Images
{
    public class TextImage : Image, ITextImage
    {
 
        /// <summary>
        /// Text rendering override
        /// </summary>
        public string Text { get; set; }
        public string FontName { get; set; }

        private SpriteFont font;


        public TextImage()
        {
        }

        protected override void Initialize()
        {
            base.Initialize();
            Text = string.Empty;
            FontName = "Fonts/Orbitron";

        }



        public override void LoadContent()
        {
            base.LoadContent();
            font = base.content.Load<SpriteFont>(FontName);
            if (Text != null || Text != "")
                ScreenManager.Instance.SpriteBatch.DrawString((SpriteFont) font, (string) Text, Vector2.Zero, Color.White);

        }

        public TextImage(string path) : base(path)
        {
        }

        public TextImage(Texture2D image) : base(image)
        {
        }

        private Vector2 CalculateDimensions()
        {
            Vector2 v = Vector2.Zero;

            if (SourceImage != null)
                v.X += SourceImage.Width;

            if (font != null) v.X += font.MeasureString(Text).X;

            if (SourceImage != null)
            {
                if (font != null)
                    v.Y = Math.Max((float)SourceImage.Height, (float)font.MeasureString(Text).Y);
                else
                    v.Y = SourceImage.Height;
            }
            else if (font != null) v.Y += font.MeasureString(Text).Y;

            return v;
        }
    }
}